package com.turing.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.turing.domain.BrandInfo;
import com.turing.service.IBrandInfoService;
import com.turing.utils.AjaxResult;
import com.turing.utils.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("brandInfo")
public class BrandInfoController {

    @Autowired
    private IBrandInfoService brandInfoService;

    /**
     * 查所有
     */
    @GetMapping("/list")
    public AjaxResult selectAll() {
        List<BrandInfo> list = brandInfoService.selectAll();
        return AjaxResult.success(list);
    }

    /**
     * 根据id 查一条
     */
    @GetMapping("/{id}")
    public BrandInfo selectById(@PathVariable() Long id) {
        return brandInfoService.selectById(id);
    }

    /**
     * 查分页
     */
    @GetMapping("/page")
    public TableDataInfo selectPage(BrandInfo brandInfo) {
        PageHelper.startPage(brandInfo.getPageNum(), brandInfo.getPageSize());

        List<BrandInfo> list = brandInfoService.selectPage(brandInfo);

        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setTotal(new PageInfo<>(list).getTotal());
        tableDataInfo.setRows(list);
        tableDataInfo.setCode(200);
        tableDataInfo.setMsg("success");
        return tableDataInfo;
    }
    /**
     * 添加
     */
    @PostMapping()
    public int insertOne(@RequestBody BrandInfo brandInfo) {
        return brandInfoService.insertOne(brandInfo);
    }

    /**
     * 修改
     */
    @PutMapping()
    public int updateById(@RequestBody BrandInfo brandInfo) {
        return brandInfoService.updateById(brandInfo);
    }

    /**
     * 删除
     */
    @DeleteMapping("/{ids}")
    public int deleteByIds(@PathVariable() Long[] ids) {
        return brandInfoService.deleteByIds(ids);
    }
}